package com.by.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ServivE
 * @version 0.1
 * @className RabbitConfig
 * @description
 * @date 2024/10/23 9:40
 * @since jdk17
 */
@Configuration
public class RabbitConfig {
    //队列
    @Bean
    public Queue queueError() {
        return new Queue(RabbitConstant.QUEUE_ERROR.toString());
    }

    @Bean
    public Queue queueInfo() {
        return QueueBuilder.durable(RabbitConstant.QUEUE_INFO.toString())
                .ttl(10000)
                .build();
    }

    //交换器
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(RabbitConstant.EXCHANGE_NAME.toString());
    }


    /**
     * 将错误队列绑定到交换器上
     * @param queueError
     * @param directExchange
     * @return
     */
    @Bean
    public Binding bindingOne(Queue queueError, DirectExchange directExchange) {
        return BindingBuilder.bind(queueError).to(directExchange).with("error");
    }

    @Bean
    public Binding bindingTwo(Queue queueInfo, DirectExchange directExchange) {
        return BindingBuilder.bind(queueInfo).to(directExchange).with("info");
    }
}
